
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Home</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/common/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/common/layui/css/layui.css">
    <script src="<%=request.getContextPath()%>/common/layui/layui.js"></script>
</head>
<body>
<ul class="layui-nav" lay-filter="">
    <li class="layui-nav-item"> <a href="javascript:;">不知名系统</a></li>
    <li class="layui-nav-item">
        <a href="javascript:;">功能模块</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a class="bts" path="user/userMain">用户管理</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item" style="float: right">
        <a href="javascript:;">个人中心</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a class="pass">修改密码</a></dd>
            <dd><a href="login/loginOut">退出登录</a></dd>
        </dl>
    </li>
</ul>

<div class="layui-container" id="mainDiv">

</div>

<script type="text/html" id="updatePass">
    <form class="layui-form layui-form-pane"  >
        <input type="text" name="name" value="${userInfo.name}">
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input lay-verify="password" type="password" name="password"  autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-btn" lay-submit lay-filter="updatePass" value="修改" />
            <input type="reset" class="layui-btn"  value="重置" />
        </div>
    </form>
</script>
</body>
<script>
    layui.use(function () {
        let element = layui.element;
        let layer = layui.layer;
        let form = layui.form;


        element.render();
        element.on("nav(updatePass)",function (res) {
            console.log(res)
        })


        $(".bts").on("click",function (res){
            $.post({
                url:"<%=request.getContextPath()%>/jump/jumpPage",
                data:{"page":res.currentTarget.attributes.path.value},
                success:function (res){
                    $("#mainDiv").html(res);
                }
            })
        })


        $(".pass").on("click",function (res) {
            layer.open({
                title:"修改密码",
                type:1,
                content:$("#updatePass").html(),
                area:"600px"
            });

            form.verify({
                password:function (value, item) {
                    if (value.length<5){
                        return "密码不能小于5位";
                    }
                    var zz = /^[A-Za-z0-9]+$/;
                    if (!zz.test(value)){
                        return "密码只能是字母和数字";
                    }
                }
            })

            form.on("submit(updatePass)",function (rs){
                var info = rs.field;
                $.post({
                    url:"<%=request.getContextPath()%>/user/updatePassword",
                    async:false,
                    data:info,
                    success:function (result) {
                        if (result.code==200){
                            location.href="login.jsp";
                        }else {
                            layer.msg(result.msg);
                        }
                    }
                })
            })
        })
    })
</script>
</html>
